package com.lovo.frame;

import com.lovo.pojo.UserDO;
import com.lovo.service.UserService;
import com.lovo.service.impl.UserServiceImpl;
import com.lovo.util.DBUtil;
import com.lovo.util.Util;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 取款
 */
public class GetPanel extends JPanel implements ActionListener {
    private ATM frame;
    private JLabel blanceLabel = new JLabel("请输入取款金额");
    private JTextField blanceTextField = new JTextField();
    private JButton sureBtn = new JButton(Util.getIcon("/images/buttonSure.jpg"));
    private JButton backBtn = new JButton(Util.getIcon("/images/buttonOff.jpg"));
    private Font font = new Font("宋体",Font.BOLD,25);
    private UserService userService = new UserServiceImpl();
    public GetPanel(ATM frame){
        this.frame = frame;
        this.setLayout(null);
        this.setOpaque(false);


        blanceLabel.setBounds(300,250,200,50);
        blanceLabel.setFont(font);
        this.add(blanceLabel);

        blanceTextField.setBounds(500,250,200,50);
        blanceTextField.setFont(font);
        this.add(blanceTextField);

        sureBtn.setBounds(350,350,140,50);
        sureBtn.addActionListener(this);
        this.add(sureBtn);

        backBtn.setBounds(520,350,140,50);
        backBtn.addActionListener(this);
        this.add(backBtn);


    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource() == sureBtn){
            try {
                double blance = Double.parseDouble(blanceTextField.getText());
                userService.getMoney(frame.getLoginUser().getId(),blance);
            } catch (Exception exception) {
                JOptionPane.showMessageDialog(this,exception.getMessage());
            }
            frame.switchPanel("menu");

        }else if(e.getSource() == backBtn){
            frame.switchPanel("menu");

        }
    }
}
